/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package proyectoaislamiento;

import Clases.*;
import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner.DefaultEditor;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Gustavo
 */
public class Principal extends javax.swing.JFrame {

    /**
     * Creates new form Principal
     */
    //ESTAS SON LAS LISTAS NECESARIAS PARA BUSCAR PARAMETROS EN LAS TABLAS
    ListaPresion presion = new ListaPresion();
    ListaVoltaje voltaje = new ListaVoltaje();
    ListaBil Bil = new ListaBil();

    public Principal() {
        initComponents();
        RealizarCarga();
        ((DefaultEditor) jSpinner1.getEditor()).getTextField().setEditable(false);
        ((DefaultEditor) jSpinner2.getEditor()).getTextField().setEditable(false);
        Presi.setText("760");
        Bmax.setText("23");
    }

    public void RealizarCarga() {
        CargaPresion Cpresion = new CargaPresion();
        CargaVoltaje Cvoltaje = new CargaVoltaje();
        CargarBil Cbil = new CargarBil();

        presion = Cpresion.Lectura();
        voltaje = Cvoltaje.Lectura();
        Bil = Cbil.Lectura();


    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        Altura = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        Bbasico = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        Vnominal = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        Presi = new javax.swing.JTextField();
        jTextField7 = new javax.swing.JTextField();
        Vmaximo = new javax.swing.JTextField();
        Bmax = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jSpinner1 = new javax.swing.JSpinner();
        jSpinner2 = new javax.swing.JSpinner();
        jSpinner3 = new javax.swing.JSpinner();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        Altura.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AlturaActionPerformed(evt);
            }
        });
        Altura.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                AlturaKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                AlturaKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                AlturaKeyTyped(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setText("Altura de Montaje:");

        jTextField2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField2ActionPerformed(evt);
            }
        });
        jTextField2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextField2KeyTyped(evt);
            }
        });

        jTextField3.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextField3KeyTyped(evt);
            }
        });

        Bbasico.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                BbasicoKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                BbasicoKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                BbasicoKeyTyped(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel2.setText("Temperatura Promedio:");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel3.setText("Numero de diametros:");

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel4.setText("BIL basico:");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel5.setText("Voltaje Nominal:");

        Vnominal.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                VnominalKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                VnominalKeyTyped(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel6.setText("Presion:");

        Presi.setEditable(false);
        Presi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PresiActionPerformed(evt);
            }
        });

        jTextField7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField7ActionPerformed(evt);
            }
        });
        jTextField7.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextField7KeyTyped(evt);
            }
        });

        Vmaximo.setEditable(false);
        Vmaximo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                VmaximoActionPerformed(evt);
            }
        });

        Bmax.setEditable(false);
        Bmax.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BmaxActionPerformed(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel7.setText("hg:");

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel8.setText("BIL maximo");

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel9.setText("Voltaje Maximo");

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel10.setText("Parametros");

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel11.setText("Tablas");

        jButton1.setText("Screenshot");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Calcular");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jSpinner1.setModel(new javax.swing.SpinnerNumberModel(0, 0, 4900, 100));
        jSpinner1.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSpinner1StateChanged(evt);
            }
        });
        jSpinner1.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jSpinner1PropertyChange(evt);
            }
        });

        jSpinner2.setModel(new javax.swing.SpinnerListModel(new String[] {"20", "40", "60", "75", "95", "125", "145", "170", "250", "325", "380", "450", "550", "650", "750", "850", "950", "1050"}));
        jSpinner2.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSpinner2StateChanged(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel8)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel4))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel10)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(Altura)
                                            .addComponent(jTextField2)
                                            .addComponent(jTextField3)
                                            .addComponent(Bbasico)
                                            .addComponent(Vnominal, javax.swing.GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE))
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addGap(41, 41, 41)
                                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                    .addComponent(jLabel6)
                                                    .addComponent(jLabel7)))
                                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jLabel9))))
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jSpinner2, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jSpinner3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(Bmax, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                            .addComponent(Presi, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextField7, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(Vmaximo))))
                .addGap(65, 65, 65))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel11)
                .addGap(139, 139, 139))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jLabel11))
                .addGap(31, 31, 31)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Altura, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel6)
                    .addComponent(Presi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Bbasico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel8)
                    .addComponent(Bmax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(Vnominal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Vmaximo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addGap(30, 30, 30)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2)
                    .addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSpinner2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSpinner3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(52, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void AlturaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AlturaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_AlturaActionPerformed

    private void PresiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PresiActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_PresiActionPerformed

    private void jTextField7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField7ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField7ActionPerformed

    private void VmaximoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_VmaximoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_VmaximoActionPerformed

    private void BmaxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BmaxActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_BmaxActionPerformed

    private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField2ActionPerformed

    private void AlturaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_AlturaKeyPressed
        //AQUI VA EL CODIGO CUANDO PRESIONE UNA TECLA
        //  Presi.setText( presion.BuscarPresion(Altura.getText()));
    }//GEN-LAST:event_AlturaKeyPressed

    private void BbasicoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_BbasicoKeyPressed
        //  Bmax.setText(Bil.BuscarMaximo(Bbasico.getText()));
    }//GEN-LAST:event_BbasicoKeyPressed

    private void AlturaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_AlturaKeyReleased
        // TODO add your handling code here:
        if (!Altura.getText().isEmpty()) {
            Presi.setText(presion.BuscarPresion(Altura.getText()));
        } else {
            Presi.setText("");
        }

    }//GEN-LAST:event_AlturaKeyReleased

    private void BbasicoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_BbasicoKeyReleased
        // TODO add your handling code here:
        if (!Bbasico.getText().isEmpty()) {
            Bmax.setText(Bil.BuscarMaximo(Bbasico.getText()));
        } else {
            Bmax.setText("");
        }

    }//GEN-LAST:event_BbasicoKeyReleased

    private void AlturaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_AlturaKeyTyped
        // TODO add your handling code here:

        char caracter = evt.getKeyChar();

        // Verificar si la tecla pulsada no es un digito
        if (Altura.getText().matches("^.*\\..*\\..*$")) {
            JOptionPane.showMessageDialog(this, "La sucesion de caracteres introducida en el campo Altura, no es valido.");
            Altura.setText("");
            evt.consume();
        }
        if (((caracter < '0') || (caracter > '9')) && (caracter != '\b' /*corresponde a BACK_SPACE*/) && (caracter != '.')) {
            evt.consume();  // ignorar el evento de teclado
        }
    }//GEN-LAST:event_AlturaKeyTyped

    private void jTextField2KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField2KeyTyped
        // TODO add your handling code here:

        char caracter = evt.getKeyChar();

        // Verificar si la tecla pulsada no es un digito
        if (((caracter < '0')
                || (caracter > '9'))
                && (caracter != '\b' /*corresponde a BACK_SPACE*/)) {
            evt.consume();  // ignorar el evento de teclado
        }
    }//GEN-LAST:event_jTextField2KeyTyped

    private void jTextField7KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField7KeyTyped
        // TODO add your handling code here:

        char caracter = evt.getKeyChar();

        // Verificar si la tecla pulsada no es un digito
        if (((caracter < '0')
                || (caracter > '9'))
                && (caracter != '\b' /*corresponde a BACK_SPACE*/)) {
            evt.consume();  // ignorar el evento de teclado
        }
    }//GEN-LAST:event_jTextField7KeyTyped

    private void jTextField3KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField3KeyTyped
        // TODO add your handling code here

        char caracter = evt.getKeyChar();

        // Verificar si la tecla pulsada no es un digito
        if (((caracter < '0')
                || (caracter > '9'))
                && (caracter != '\b' /*corresponde a BACK_SPACE*/)) {
            evt.consume();  // ignorar el evento de teclado
        }
    }//GEN-LAST:event_jTextField3KeyTyped

    private void BbasicoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_BbasicoKeyTyped
        // TODO add your handling code here:

        char caracter = evt.getKeyChar();

        // Verificar si la tecla pulsada no es un digito
        if (((caracter < '0')
                || (caracter > '9'))
                && (caracter != '\b' /*corresponde a BACK_SPACE*/)) {
            evt.consume();  // ignorar el evento de teclado
        }
    }//GEN-LAST:event_BbasicoKeyTyped

    private void VnominalKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_VnominalKeyTyped
        // TODO add your handling code here:

        char caracter = evt.getKeyChar();

        // Verificar si la tecla pulsada no es un digito
        if (((caracter < '0')
                || (caracter > '9'))
                && (caracter != '\b' /*corresponde a BACK_SPACE*/)) {
            evt.consume();  // ignorar el evento de teclado
        }
    }//GEN-LAST:event_VnominalKeyTyped

    private void VnominalKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_VnominalKeyReleased
        // TODO add your handling code here:
        if (!Vnominal.getText().isEmpty()) {
            Vmaximo.setText(voltaje.BuscarMaximo(Vnominal.getText()));
        } else {
            Vmaximo.setText("");
        }
    }//GEN-LAST:event_VnominalKeyReleased

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        try {
            // TODO add your handling code here:

            Robot robot = new Robot();
            BufferedImage image = robot.createScreenCapture(new Rectangle(500, 500));
            String path = new File("").getAbsolutePath() + "captura.jpg";
            ImageIO.write(image, "jpg", new File(path));

        } catch (AWTException ex) {
            Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
        }


    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        //validar
        String str_AlturaDeMontaje = Altura.getText();
        String str_TemperaturaPromedio = jTextField2.getText();
        String str_hg = jTextField7.getText();
        String str_NumeroDeDiametros = jTextField3.getText();
        String str_BilBasico = Bbasico.getText();
        String str_VoltajeNominal = Vnominal.getText();

        if ("".equals(str_AlturaDeMontaje)) {
            JOptionPane.showMessageDialog(this, "La Altura de Montaje no puede estar vacía.", "Error", JOptionPane.ERROR_MESSAGE);
            return;
        } else if (str_TemperaturaPromedio.equals("")) {
            JOptionPane.showMessageDialog(this, "La Temperatura Promedio no puede estar vacía.", "Error", JOptionPane.ERROR_MESSAGE);
            return;
        } else if (str_hg.equals("")) {
            JOptionPane.showMessageDialog(this, "HG no puede ser un campo vacio.", "Error", JOptionPane.ERROR_MESSAGE);
            return;
        } else if (str_NumeroDeDiametros.equals("")) {
            JOptionPane.showMessageDialog(this, "El numero de diametros no puede estar vacio.", "Error", JOptionPane.ERROR_MESSAGE);
            return;
        } else if (str_BilBasico.equals("")) {
            JOptionPane.showMessageDialog(this, "El Bil Basico no puede estar vacio.", "Error", JOptionPane.ERROR_MESSAGE);
            return;
        } else if (str_VoltajeNominal.equals("")) {
            JOptionPane.showMessageDialog(this, "El Voltaje Nominal no puede estar vacio.", "Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
        double parametro_BilMaximo = Double.parseDouble(Bmax.getText());
        double parametro_presion = Double.parseDouble(Presi.getText());
        double parametro_VoltajeMaximo = Double.parseDouble(Vmaximo.getText());


        //casteamos las cadenas a double
        double parametro_AlturaDeMontaje;
        double parametro_TemperaturaPromedio;
        double parametro_hg;
        double parametro_NumeroDeDiametros;
        double parametro_BilBasico;
        double parametro_VoltajeNominal;

        try {
            parametro_AlturaDeMontaje = Double.parseDouble(str_AlturaDeMontaje);
            parametro_TemperaturaPromedio = Double.parseDouble(str_TemperaturaPromedio);
            parametro_hg = Double.parseDouble(str_hg);
            parametro_NumeroDeDiametros = Double.parseDouble(str_NumeroDeDiametros);
            parametro_BilBasico = Double.parseDouble(str_BilBasico);
            parametro_VoltajeNominal = Double.parseDouble(str_VoltajeNominal);
        } catch (Exception e) {
            System.out.println(e.getCause());
            return;
        }
        /*
         alturaDeMontaje temperaturaPromedio numeroDeDiametros bilBasico voltajeNominal presion hg bilMaximo voltajeMaximo */

        Calcular(parametro_AlturaDeMontaje, parametro_TemperaturaPromedio, parametro_NumeroDeDiametros, parametro_BilBasico, parametro_VoltajeNominal, parametro_presion, parametro_hg, parametro_BilMaximo, parametro_VoltajeMaximo);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jSpinner1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSpinner1StateChanged
        // TODO add your handling code here:
        if (!jSpinner1.getValue().toString().isEmpty()) {
            Presi.setText(presion.BuscarPresion(jSpinner1.getValue().toString()));
//            System.out.println("" + jSpinner1.getValue().toString());
        } else {
            Presi.setText("");
//            System.out.println("else2");
        }
    }//GEN-LAST:event_jSpinner1StateChanged

    private void jSpinner1PropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jSpinner1PropertyChange
        // TODO add your handling code here:
    }//GEN-LAST:event_jSpinner1PropertyChange

    private void jSpinner2StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSpinner2StateChanged
        // TODO add your handling code here:
         if (!jSpinner2.getValue().toString().isEmpty()) {
            Bmax.setText(Bil.BuscarMaximo(jSpinner2.getValue().toString()));
        } else {
            Bmax.setText("");
        }
    }//GEN-LAST:event_jSpinner2StateChanged

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Principal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField Altura;
    private javax.swing.JTextField Bbasico;
    private javax.swing.JTextField Bmax;
    private javax.swing.JTextField Presi;
    private javax.swing.JTextField Vmaximo;
    private javax.swing.JTextField Vnominal;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JSpinner jSpinner1;
    private javax.swing.JSpinner jSpinner2;
    private javax.swing.JSpinner jSpinner3;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField7;
    // End of variables declaration//GEN-END:variables

    /**
     *
     * @param alturaDeMontaje
     * @param temperaturaPromedio
     * @param numeroDeDiametros
     * @param bilBasico
     * @param voltajeNominal
     * @param presion
     * @param hg
     * @param bilMaximo
     * @param voltajeMaximo
     */
    private void Calcular(double alturaDeMontaje, double temperaturaPromedio,
            double numeroDeDiametros, double bilBasico, double voltajeNominal,
            double presion, double hg, double bilMaximo, double voltajeMaximo) {
        Calculos c;
        try {
            c = new Calculos(alturaDeMontaje, temperaturaPromedio, numeroDeDiametros, bilBasico, voltajeNominal, presion, hg, bilMaximo, voltajeMaximo);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Error al instanciar la clase.", "Error de instancia", JOptionPane.ERROR_MESSAGE);
            return;
        }
        try {
            //recuperando valores
            double densidad = c.Densidad(temperaturaPromedio, presion);
            double dft = c.dft(bilBasico, hg, densidad);
            double dff = c.dff(dft);
            double y_fase_tierra = c.Y_FaseATierra_BilBasico(dff, dft);

            double dftpa = c.dft_polosAbiertos(bilMaximo, hg, densidad);
            double dbb_1_8 = c.dbb_1_8(dft);
            double dbb_2 = c.dbb_2(dft);
            double distancia_dbb_1_8 = c.distancia_dbb_1_8(dbb_1_8, dft);
            double distancia_dbb_2 = c.distancia_dbb_2(dbb_2, dft);
            double dvp = c.dvp(dft);
            double dhp = c.dhp(dft);
            double dhp_seccionador = c.dhp_seccionador_ct(dhp, dftpa);
            double seccionador_a_estruc = c.seccionador_a_estruc(dft, dftpa);
            double dhv = c.dhv(dft);
            double dhv_de_calle = c.dhvDeCalle(dft);
            double dp_pt = c.dp_pt(dft);
            double dvv = c.dvv(dft);
            double he = c.he(voltajeMaximo);
            double hemsnm = c.he_msnm(he, alturaDeMontaje);
            double hb = c.hb(voltajeMaximo);
            double hbmsnm = c.hb_msnm(hb, alturaDeMontaje);
            double hl = c.hl(voltajeMaximo);
            double hlmsnm = c.hl_msnm(hl, alturaDeMontaje);
            double A1 = c.A1_fi(dft, dftpa);
            double At_fi = c.At_fi(A1);
            double At = c.At(At_fi, numeroDeDiametros);
            double h_fase_tierra = c.H_FaseATierra_BilBasico(y_fase_tierra, hbmsnm);
            String resultados =
                    "δ (Densidad:\t\t)" + densidad + "\n"
                    + "DFT:      \t\t" + dft + "\n"
                    + "Y:        \t\t" + y_fase_tierra + "\n"
                    + "H:        \t\t" + h_fase_tierra + "\n"
                    + "DFT entre polos Abiertos: " + dftpa + "\n"
                    + "DBB(1.8):        \t\t" + dbb_1_8 + "\n"
                    + "DBB(2.0):         \t\t" + dbb_2 + "\n"
                    + "Distancia de Barra total (1.8):          " + distancia_dbb_1_8 + "\n"
                    + "Distancia de Barra total (2.0):          " + distancia_dbb_2 + "\n"
                    + "Distancia de trabajo Vertical para personas:             " + dvp + "\n"
                    + "Distancia de trabajo Horizontal:         " + dhp + "\n"
                    + "Distancia de trabajo Horizontal Seccionador CT:          " + dhp_seccionador + "\n"
                    + "Distancia de trabajo Horizontal Seccionador a Estructura:        " + seccionador_a_estruc + "\n"
                    + "Distancia Horizontal de vehiculos:       " + dhv + "\n"
                    + "Distancia Horizontal de Calle:       " + dhv_de_calle + "\n"
                    + "Distancia entre Pararrayos y PT:         " + dp_pt + "\n"
                    + "Distancia Vertical para circulacion de vehiculos:        " + dvv + "\n"
                    + "Primer Nivel de Barras o Altura de equipo:       " + he + "\n"
                    + "Primer Nivel de Barras o Altura de equipo (Metros sobre el nivel del mar):       " + hemsnm + "\n"
                    + "Altura de remate de lineas que entran en subestacion:        " + hl + "\n"
                    + "Altura de remate de lineas que entran en subestacion (Metros sobre el nivel del mar):        " + hlmsnm + "\n"
                    + "Ancho de un diametro:        " + dff + "\n"
                    + "A1(fi):      " + A1 + "\n"
                    + "At(fi):      " + At_fi + "\n"
                    + "Ancho Total:         " + At + "\n";

            final JTable table = new JTable(10, 5) {
                @Override
                public Dimension getPreferredScrollableViewportSize() {
                    Dimension dim = super.getPreferredScrollableViewportSize();
                    // here we return the pref height
                    dim.height = getPreferredSize().height;
                    return dim;
                }
            };
            final JComponent content = new JPanel();
            content.add(new JScrollPane(table));
            Action add = new AbstractAction("add row") {
                @Override
                public void actionPerformed(ActionEvent e) {
                    ((DefaultTableModel) table.getModel()).addRow(new Object[]{"Densidad"});
                    content.revalidate();
                }
            };


//            Object[] columnas = {"Propiedad", "Resultado"};
//            Object[] fila1 = {"Densidad", densidad};
//            DefaultTableModel dtm = new DefaultTableModel(columnas, 10);
//            dtm.addRow(fila1);
//            JTable TablaDeResultados = new JTable(dtm);

            JOptionPane.showMessageDialog(this, resultados, "Resultados", JOptionPane.INFORMATION_MESSAGE);

        } catch (Exception ex) {
            Logger.getLogger(Calculos.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
